package com.sztx.pay.data.transfer;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.io.FileUtils;

import com.sztx.commons.util.excel.ExcelLogs;
import com.sztx.commons.util.excel.ExcelUtil;
import com.sztx.commons.util.excel.ExcelUtil.ExcelType;
import com.sztx.pay.data.transfer.bean.UserInfo;
import com.sztx.pay.data.transfer.util.IDCardUtil;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws IOException
    {
    	
    	List<String> list = FileUtils.readLines(new File("C:\\Users\\xiaosc\\Desktop\\test.txt"));
    	
    	Set<String> set = new HashSet<String>(list);
	
    	System.out.println(list.size());    	
    	
    	
//    	for (int i = 0; i < 100; i++) {
//			System.out.println(list.get(i));
//		}
    	
    	
    	
    	
        File file = new File("C:\\Users\\xiaosc\\Desktop\\UserBaseInfo.xlsx");
//		List<String> list = FileUtils.readLines(file, "gbk");
//		for (int i = 0; i < 100; i++) {
//			String userInfo = list.get(i);
//			
//			System.out.println(userInfo);
//			String[] datas = userInfo.split(",");
//			
//			System.out.println(datas.length);
//			
//			String userId = datas[0];
//			String telphone = datas[1];
//			String mob = datas[2];
//			String userState = datas[3];
//			String realName = datas[4];
//			String identityNum = datas[5];
//			String verified = datas[6];
//			
//			System.out.println(userId+" "+telphone+" "+mob+" "+userState+" "+realName+" "+identityNum+" "+verified);
//		}
//		
        ExcelLogs logs =new ExcelLogs();
        InputStream inputStream= new FileInputStream(file);
		Collection<UserInfo> userList = ExcelUtil.importExcel(UserInfo.class, inputStream, null, logs, ExcelType.XSSF, 0);
		
		System.out.println(userList.size());
		
//		int i = 0;
		
		
		List<UserInfo> transferList = new ArrayList<UserInfo>();
		
		int i = 0;
		int j = 0;
		int k = 0;
		int m = 0;
		
		
		List<String> unRealNameUserList = new ArrayList<String>();
		
		for (UserInfo userInfo : userList) {
			
			String userId = userInfo.getUserId();
			if (userId == null) {
				i++;
				continue;
			}
			
			if (!set.remove(userId)) {				
				String verified = userInfo.getVerified();
				if (verified == null || !verified.trim().equals("1")) {
					j++;
					System.out.println(userId+"用户未实名认证，"+verified);
					unRealNameUserList.add(userId);
					continue;
				}
				
				String idcard = userInfo.getIdentityNum();
				
				if (!IDCardUtil.isIDCard(idcard)) {
					k++;
					System.out.println(userId+"用户身份证不合法,"+idcard);
					unRealNameUserList.add(userId);
					continue;
				}
				
				transferList.add(userInfo);
			}else {
				m ++;
			}
		}
		
		
		
		System.out.println("没有berbon账号用户数："+i);
		System.out.println("未实名berbon账号用户数："+j);
		System.out.println("身份证不合法berbon账号用户数："+k);
		System.out.println("代理商berbon账号用户数："+m);
		
		System.out.println("需要迁移的用户个数："+transferList.size());
		
		FileOutputStream fos = new FileOutputStream(new File("transfer_user.xls"));
		
		String[] headers = new String[]{"partner_user_id","telphone","mob","user_state","real_name","identity_num","real_name_verified"};
		ExcelUtil.exportExcel(headers , transferList, fos);
		
		System.out.println("未找到的代理商用户："+set);
		
		
		FileUtils.writeLines(new File("user_list.txt"), unRealNameUserList, "UTF-8");
		
    }
}
